//----- imagePreview ------
//----- attempt to make a jquery plugin ---natz
//usage:  
//$('#img-preview').preview('#input-image');
// img-preview - id of img elemet for preview
// input-image - id of input[type=file]

(function( $ ) {
  $.fn.multiselect = function(table) {
    var dataTable = document.createElement('div');
    document.body.appendChild(dataTable);
    dataTable = $(dataTable);
    dataTable.css('display', 'none').css('position', 'absolute').css('top', '0px').css('left', '0px').append(table);
    this.click(function(){
      dataTable.show();
      dataTable.css('top', $(this).offset().top + $(this).outerHeight() + 'px').css('left', $(this).offset().left + 'px');
    });
    var self = this;
    $(document).click(function(e){
      if(e.target !== self[0] && e.target !== dataTable[0]){
        dataTable.hide();
      }
      console.log(dataTable[0]);
      console.log(e.target);
    })
    return this;
  };
})( jQuery );


$(document).ready(function(){
  $('#test-text').multiselect('<div class="scroll-content color-white"><table class="data-list width-100-percent" cellspacing="0"><tr><th>Key</th><th>Fruit</th></tr>'
      + '<tr><td class="list-1">1</td><td class="list-2">Apple</td></tr>'
      +'</table></div>');
});
